//
//  APIRequestClient.h
//  XWKit
//
//  Created by xiaowuxiaowu on 16/3/26.
//  Copyright © 2016年 xiaowuxiaowu. All rights reserved.
//



#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>

@class Responese;

typedef void(^successBlock)(NSURLSessionDataTask *task, id responseObject,Responese *respone);
typedef void(^failureBlock)(NSURLSessionDataTask *task, NSError *error,Responese *respone);
typedef void(^nonetWorkBlock)(NSURLSessionDataTask *task, NSError *error);


@interface APIRequestClient : NSObject

@property (nonatomic,copy)NSURLSessionDataTask *dataTask;
@property (nonatomic,copy)NSURLSessionDownloadTask *downLoadTask;
@property (nonatomic,copy)AFHTTPSessionManager *httpManager;




/*  POST 请求
 *  urlString  url
 *  parameters 字典
 *
 */
-(void)POST:(NSString * )urlString parameters:(id)parameters
      progress:( void (^)( NSProgress * uploadProgress)) uploadProgress
     success:(successBlock)success
     failure:(failureBlock)failure
     nonetWork:(nonetWorkBlock)nonetWorkBlock;



-(void)GET:(NSString * )urlString parameters:( id)parameters
  progress:( void (^)( NSProgress * uploadProgress)) uploadProgress
   success:(successBlock)success
   failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock;


/*  下载
 *  urlString  url
 *  filePath 下载路径
 *
 */
- (void)downloadTaskWithUrl:(NSString *)urlString
                   progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock
                destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
          completionHandler:(void (^)(NSURLResponse *response, NSURL * filePath, NSError *  error))completionHandler;


/*  上传
 *  urlString  url
 *  fileURL 上传路径
 *
 */
- (NSURLSessionUploadTask *)uploadTaskWithUrlString:(NSString *)urlString parameters:( id)parameters  mimeType:(NSString *)mimeType sourceData:(NSData*)sourceData
                                           progress:(void (^)(NSProgress * downloadProgress)) downloadProgressBlock
                                  completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;

-(void)uploadTaskWithStreamedRequest;


-(void)other_post:(NSString * )urlString parameters:( id)parameters
         progress:( void (^)( NSProgress * uploadProgress)) uploadProgress
          success:(successBlock)success
          failure:(failureBlock)failure;
-(void)other_get:(NSString * )urlString parameters:( id)parameters
        progress:( void (^)( NSProgress * uploadProgress)) uploadProgress
         success:(successBlock)success
         failure:(failureBlock)failure;


+ (NSDictionary *)tp_dictionaryWithJSON:(id)json;

@end



@interface Responese : NSObject
@property(strong, nonatomic) AFHTTPSessionManager* afom;

@property(strong, nonatomic) NSString *timeDate;
@property(assign, nonatomic) BOOL status;
@property(strong, nonatomic) NSString *message;
@property(strong, nonatomic) id data;
@property(strong, nonatomic) NSString *text;
@property(strong, nonatomic) NSError *error;
@property(assign, nonatomic) NSInteger code;

@end
